// 基于 SnowLang Project (https://gitee.com/jcnc-org/snow) 的衍生作品
// 原始版权归属: Copyright © 2025 Ke Xu (Luke)
// 本实现版权归属: Copyright © 2025 Sany
// 遵循 Apache License 2.0 授权
package vm

import (
	"gitee.com/xntk2381/cc/vm/engine"
	"gitee.com/xntk2381/cc/vm/execution"
	"gitee.com/xntk2381/cc/vm/io"
	"gitee.com/xntk2381/cc/vm/module"
	"gitee.com/xntk2381/cc/vm/utils"
)

func initializeAndRunVM(args []string, vmMode module.VMMode) {
	filePath := io.FilePathResolver.GetFilePath(args)
	if filePath == "" {
		return
	}
	commands := execution.CommandLoader.LoadInstructions(filePath)
	if len(commands) == 0 {
		return
	}
	virtualMachineEngine := engine.NewVirtualMachineEngine(vmMode)
	engine.VMCommandExecutor.ExecuteInstructions(virtualMachineEngine, commands)

	utils.VMStateLogger.PrintVMState(virtualMachineEngine)
}
